﻿using System.ComponentModel;
using AMatysiak.Converters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;

namespace AMatysiakTest
{
    [TestClass]
    public class CurrencyConverterTest
    {
        private class Money
        {
            private double cash;
            [TypeConverter(typeof(CurrencyConverter))]
            public double Cash
            {
                get { return cash; }
                set { cash = value; }
            }
        }

        [TestMethod]
        public void TestConverter()
        {
            Money money = new Money();
            money.Cash = 2.55;

            PropertyGrid grid = new PropertyGrid();
            grid.SelectedObject = money;
            GridItem item = grid.SelectedGridItem;
            PropertyDescriptor pd = item.PropertyDescriptor;
            TypeConverter conv = pd.Converter;
            string cash = conv.ConvertTo(money.Cash, typeof(string)).ToString();

            Assert.AreEqual((2.55).ToString("C2"), cash);
        }
    }
}
